PHP_ARG_WITH(
	[openal],
	[if OpenAL support should be built],
	[  --with-openal            Enable OpenAL support]
)

if test "$PHP_OPENAL" != "no"; then

	AC_DEFINE(
		[WITH_OPENAL],
		1,
		[if OpenAL support should be built]
	)
	
	AC_MSG_CHECKING([for AL/al.h, AL/alc.h, and AL/alut.h])
	for i in $PHP_OPENAL /usr/local /usr; do
		if test -r $i/include/AL/al.h; then
			OPENAL_DIR=$i
			AC_DEFINE(HAVE_AL_H, 1, [Whether you have AL/al.h])
			PHP_ADD_INCLUDE($i/include)
		fi
		if test -r $i/include/AL/alc.h; then
			AC_DEFINE(HAVE_ALC_H, 1, [Whether you have AL/alc.h])
			PHP_ADD_INCLUDE($i/include)
		fi
		if test -r $i/include/AL/alut.h; then
			AC_DEFINE(HAVE_ALUT_H, 1, [Whether you have AL/alut.h])
			PHP_ADD_INCLUDE($i/include)
		fi
		if test -r $i/include/AL/alext.h; then
			AC_DEFINE(HAVE_ALEXT_H, 1, [Whether you have AL/alext.h])
			PHP_ADD_INCLUDE($i/include)
		fi
	done

	if test -z "$OPENAL_DIR"; then
		AC_MSG_RESULT([not found])
		AC_MSG_ERROR([Please reinstall the OpenAL distribution including development files])
	else
		AC_MSG_RESULT([found])
	fi

	AC_CHECK_LIB(openal, alcOpenDevice, [PHP_ADD_LIBRARY(openal,, OPENAL_SHARED_LIBADD)], [AC_MSG_ERROR([libopenal.so not found!])])
	AC_CHECK_LIB(alut, alutInit, [PHP_ADD_LIBRARY(alut,, OPENAL_SHARED_LIBADD)], [AC_MSG_ERROR([libalut.so not found!])])
	AC_CHECK_LIB(openal, alGenStreamingBuffers_LOKI, [AC_DEFINE(HAVE_OPENAL_STREAM, 1, [Whether you have suport for OpenAL streaming])],)

	PHP_SUBST(OPENAL_SHARED_LIBADD)

	PHP_NEW_EXTENSION(
		[openal],
		[src/php_openal.c src/openal.c src/class_openal.c src/class_openalbuffer.c src/class_openalsource.c],
		[$ext_shared],
		[]
	)

fi
	
